package com.stylefeng.guns.biz.table.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.biz.table.model.TTableList;
import com.stylefeng.guns.biz.table.service.ITTableListService;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;

/**
 * 四方格控制器
 *
 * @author fengshuonan
 * @Date 2018-06-14 06:25:39
 */
@Controller
@RequestMapping("/tTableList")
public class TTableListController extends BaseController {

    private String PREFIX = "/app/tTableList/";

    @Autowired
    private ITTableListService tTableListService;

    /**
     * 跳转到四方格首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tTableList.html";
    }

    /**
     * 跳转到添加四方格
     */
    @RequestMapping("/tTableList_add")
    public String tTableListAdd() {
        return PREFIX + "tTableList_add.html";
    }

    /**
     * 跳转到修改四方格
     */
    @RequestMapping("/tTableList_update/{tTableListId}")
    public String tTableListUpdate(@PathVariable Long tTableListId, Model model) {
        TTableList tTableList = tTableListService.selectById(tTableListId);
        model.addAttribute("item",tTableList);
        LogObjectHolder.me().set(tTableList);
        return PREFIX + "tTableList_edit.html";
    }

    /**
     * 获取四方格列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String appid) {
    	EntityWrapper<TTableList> wrapper=new EntityWrapper<>();
    	wrapper.eq("app_id_key", appid);
        return tTableListService.selectList(wrapper);
    }

    /**
     * 新增四方格
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TTableList tTableList) {
        tTableListService.insert(tTableList);
        return SUCCESS_TIP;
    }

    /**
     * 删除四方格
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long tTableListId) {
        tTableListService.deleteById(tTableListId);
        return SUCCESS_TIP;
    }

    /**
     * 修改四方格
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TTableList tTableList) {
        tTableListService.updateById(tTableList);
        return SUCCESS_TIP;
    }

    /**
     * 四方格详情
     */
    @RequestMapping(value = "/detail/{tTableListId}")
    @ResponseBody
    public Object detail(@PathVariable("tTableListId") Long tTableListId) {
        return tTableListService.selectById(tTableListId);
    }
}
